#ifndef _TIME_H
#define _TIME_H

#include <cnix/types.h>

struct timeval{
	time_t tv_sec;
	suseconds_t tv_usec;
};

struct timezone{
	int tz_minuteswest;
	int tz_dsttime;
};

struct utimbuf 
{
	time_t actime;
	time_t modtime;
};

/*
 * Check at compile time that something is of a particular type.
 * Always evaluates to 1 so you may use it easily in comparisons.
 */
#define typecheck(type,x) \
({  type __dummy; \
  typeof(x) __dummy2; \
  (void)(&__dummy == &__dummy2); \
  1; \
})

/*
 *  These inlines deal with timer wrapping correctly. You are 
 *  strongly encouraged to use them
 *  1. Because people otherwise forget
 *  2. Because if the timer wrap changes in future you won't have to
 *     alter your driver code.
 *
 * time_after(a,b) returns true if the time a is after time b.
 *
 * Do this with "<0" and ">=0" to only test the sign of the result. A
 * good compiler would generate better code (and a really good compiler
 * wouldn't care). Gcc is currently neither.
 */
#define time_after(a,b)   \
  (typecheck(unsigned long, a) && \
   typecheck(unsigned long, b) && \
   ((long)(b) - (long)(a) < 0))
#define time_before(a,b)  time_after(b,a)

#endif
